package com.zzu.chat.chat.detail.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.PagerAdapter;

import java.util.List;
/**
 * 此类被用来实现tab与viewpager结合
 * 使用参见{@link cn.edu.caztc.myapp.fragment.MainFragment#viewPager }
 * */

public class Comments_PagerAdapter extends PagerAdapter {
    List<View> list;
    Context context;
    List<String> titles;

    public Comments_PagerAdapter(List<View> list,List<String> titles){
        this.list = list;
        this.titles = titles;
    }
    //不使用titles
    public Comments_PagerAdapter(List<View> list){
        this.list = list;
    }
    public Comments_PagerAdapter() {
        super();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return titles.get(position);
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        container.addView(list.get(position));
        return list.get(position);
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView(list.get(position));

    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @Override
    public int getItemPosition(@NonNull Object object) {
        return super.getItemPosition(object);
    }

    @Override
    public int getCount() {
        return list.size();
    }
}

